package com.my.admin.util;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper;
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.my.admin.annotation.CleanCache;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @author My
 * 为适应缓存封装的ServiceImpl类
 */
public class ServiceImplCache<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {

    @Override
    @CachePut(value = "save")
    @CleanCache(classCache = true)
    public boolean save(T entity) {
        return super.save(entity);
    }

    @Override
    @CachePut(value = "saveBatch")
    @CleanCache(classCache = true)
    public boolean saveBatch(Collection<T> entityList) {
        return super.saveBatch(entityList);
    }

    @Override
    @CachePut(value = "saveOrUpdateBatch")
    @CleanCache(classCache = true)
    public boolean saveOrUpdateBatch(Collection<T> entityList) {
        return super.saveOrUpdateBatch(entityList);
    }

    @Override
    @CacheEvict(value = "removeById", allEntries = true)
    @CleanCache(classCache = true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @Override
    @CacheEvict(value = "removeByMap", allEntries = true)
    @CleanCache(classCache = true)
    public boolean removeByMap(Map<String, Object> columnMap) {
        return super.removeByMap(columnMap);
    }

    @Override
    @CacheEvict(value = "remove", allEntries = true)
    @CleanCache(classCache = true)
    public boolean remove(Wrapper<T> queryWrapper) {
        return super.remove(queryWrapper);
    }

    @Override
    @CacheEvict(value = "removeByIds", allEntries = true)
    @CleanCache(classCache = true)
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }

    @Override
    @CacheEvict(value = "updateById", allEntries = true)
    @CleanCache(classCache = true)
    public boolean updateById(T entity) {
        return super.updateById(entity);
    }

    @Override
    @CacheEvict(value = "update", allEntries = true)
    @CleanCache(classCache = true)
    public boolean update(Wrapper<T> updateWrapper) {
        return super.update(updateWrapper);
    }

    @Override
    @CacheEvict(value = "update", allEntries = true)
    @CleanCache(classCache = true)
    public boolean update(T entity, Wrapper<T> updateWrapper) {
        return super.update(entity, updateWrapper);
    }

    @Override
    @CacheEvict(value = "updateBatchById", allEntries = true)
    @CleanCache(classCache = true)
    public boolean updateBatchById(Collection<T> entityList) {
        return super.updateBatchById(entityList);
    }

    @Override
    @Cacheable(value = "getById")
    public T getById(Serializable id) {
        return super.getById(id);
    }

    @Override
    @Cacheable(value = "listByIds")
    public List<T> listByIds(Collection<? extends Serializable> idList) {
        return super.listByIds(idList);
    }

    @Override
    @Cacheable(value = "listByMap")
    public List<T> listByMap(Map<String, Object> columnMap) {
        return super.listByMap(columnMap);
    }

    @Override
    @Cacheable(value = "getOne")
    public T getOne(Wrapper<T> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Override
    @Cacheable(value = "count")
    public int count() {
        return super.count();
    }

    @Override
    @Cacheable(value = "count")
    public int count(Wrapper<T> queryWrapper) {
        return super.count(queryWrapper);
    }

    @Override
    @Cacheable(value = "list")
    public List<T> list(Wrapper<T> queryWrapper) {
        return super.list(queryWrapper);
    }

    @Override
    @Cacheable(value = "list")
    public List<T> list() {
        return super.list();
    }

    @Override
    @Cacheable(value = "page")
    public <E extends IPage<T>> E page(E page, Wrapper<T> queryWrapper) {
        return super.page(page, queryWrapper);
    }

    @Override
    @Cacheable(value = "page")
    public <E extends IPage<T>> E page(E page) {
        return super.page(page);
    }

    @Override
    @Cacheable(value = "listMaps")
    public List<Map<String, Object>> listMaps(Wrapper<T> queryWrapper) {
        return super.listMaps(queryWrapper);
    }

    @Override
    @Cacheable(value = "listMaps")
    public List<Map<String, Object>> listMaps() {
        return super.listMaps();
    }

    @Override
    @Cacheable(value = "listObjs")
    public List<Object> listObjs() {
        return super.listObjs();
    }

    @Override
    @Cacheable(value = "listObjs")
    public <V> List<V> listObjs(Function<? super Object, V> mapper) {
        return super.listObjs(mapper);
    }

    @Override
    @Cacheable(value = "listObjs")
    public List<Object> listObjs(Wrapper<T> queryWrapper) {
        return super.listObjs(queryWrapper);
    }

    @Override
    @Cacheable(value = "listObjs")
    public <V> List<V> listObjs(Wrapper<T> queryWrapper, Function<? super Object, V> mapper) {
        return super.listObjs(queryWrapper, mapper);
    }

    @Override
    @Cacheable(value = "pageMaps")
    public <E extends IPage<Map<String, Object>>> E pageMaps(E page, Wrapper<T> queryWrapper) {
        return super.pageMaps(page, queryWrapper);
    }

    @Override
    @Cacheable(value = "pageMaps")
    public <E extends IPage<Map<String, Object>>> E pageMaps(E page) {
        return super.pageMaps(page);
    }

    @Override
    @Cacheable(value = "query")
    public QueryChainWrapper<T> query() {
        return super.query();
    }

    @Override
    @Cacheable(value = "lambdaQuery")
    public LambdaQueryChainWrapper<T> lambdaQuery() {
        return super.lambdaQuery();
    }

    @Override
    @Cacheable(value = "ktQuery")
    public KtQueryChainWrapper<T> ktQuery() {
        return super.ktQuery();
    }

    @Override
    @Cacheable(value = "ktUpdate")
    public KtUpdateChainWrapper<T> ktUpdate() {
        return super.ktUpdate();
    }

    @Override
    @Cacheable(value = "update")
    public UpdateChainWrapper<T> update() {
        return super.update();
    }

    @Override
    @Cacheable(value = "lambdaUpdate")
    public LambdaUpdateChainWrapper<T> lambdaUpdate() {
        return super.lambdaUpdate();
    }

    @Override
    @CachePut(value = "saveOrUpdate")
    @CleanCache(classCache = true)
    public boolean saveOrUpdate(T entity, Wrapper<T> updateWrapper) {
        return super.saveOrUpdate(entity, updateWrapper);
    }
}
